#!/bin/sh
# Android Server init script.

BINARY="/app/spacecast/androidserver"

FLAGS="-port=8000"

running() {
  [ -n "$(pgrep -f "$BINARY")" ]
}

case "$1" in
  start)
    if running; then
      echo "Android Server is already running!"
    else
      babysit 10 ${BINARY} ${FLAGS} 2>&1 | logos androidserver &
    fi
    ;;
  stop)
    pkill -f "$BINARY"
    ;;
  restart|reload)
    $0 stop;$0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
